﻿1089.复写零
class Solution {
public:
    void duplicateZeros(vector<int>& arr) {
        int len = arr.size() - 1;
        int dest = -1, cur = 0;

        while (cur <= len)
        {
            if (arr[cur] == 0)
            {
                dest += 2;
            }
            else
            {
                dest++;
            }

            if (dest >= len)
            {
                break;
            }

            cur++;
        }

        if (dest > len)
        {
            arr[dest - 1] = 0;
            dest -= 2;
            cur--;
        }

        while (cur >= 0)
        {
            if (arr[cur] == 0)
            {
                arr[dest--] = 0;
                arr[dest--] = 0;

            }
            else
            {
                arr[dest--] = arr[cur];
            }

            cur--;
        }
    }
};

283.移动零
class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        int cur = 0, dest = -1;

        while (cur < nums.size())
        {
            if (nums[cur] != 0)
            {
                dest++;
                swap(nums[dest], nums[cur]);
            }

            cur++;
        }
    }
};